#coding=utf-8
"""
Author:高鑫
Time:2025/8/28 0028 14:31
"""

import  unittest
from time import *

class BasePage(unittest.TestCase):
    @classmethod
    def set_driver(cls,dirver):
        cls.driver = driver
    @classmethod
    def get_driver(cls):
        return cls.driver
    @classmethod
    def find_element(cls,element):
        type = element[0]
        value = element[1]

        if type == "id":
            element =cls.driver.find_element_by_id(value)
        elif type =="class":
            element =cls.driver.find_element_by_class_name(value)
        elif type =="xpath":
            element = cls.driver.find_element_by_xpath(value)
        elif type == "name":
            element =cls.driver.find_element_by_name(value)
        elif type =="css":
            element = cls.driver.find_element_by_css_seltector(value)
        elif type == "link_text":
            element = cls.driver.find_element_by_link_text(value)
        elif type == "partial":
            element = cls.driver.find_element_by_partial_link_text(value)
        else:
            raise ValueError("请输入正确的定位方式")
        return element
    @classmethod
    def sendkeys(cls,element,text):
        return element.send_keys(text)
    @classmethod
    def click(cls,element):
        return element.click()
    def wait(cls,sec):
        return cls.driver.implicitly_wait(sec)
    @classmethod
    def sleep(cls,sec):
        return sleep(sec)
    @classmethod
    def frame(cls,element):
        return cls.driver.switch_to.frame(element)
    @classmethod
    def outframe(cls):
        return driver.switch_to.default_content()
    @classmethod
    def get_text(cls,element):
        value = BasePage.find_element(elem).text
        return value
if __name__ == '__main__':
    from selenium import webdriver
    driver = webdriver.Chrome()
    BasePage.set_driver(driver)
    driver = BasePage.get_driver()
    driver.get("http://www.baidu.com")
    driver.maximize_window()
    baidu_input = ('id','chat-textarea')
    elem = BasePage.find_element(baidu_input)
    BasePage.sendkeys(elem,'dcs65')

